$(function(){
	
	var getcode = false
	var stid = null
	var timeot = null
	
	
	var pt = ""
	
	
	$('.pt li').on('click', function () {
        $(this).addClass('selected').siblings().removeClass('selected');
        
        pt = $(this).attr("data")
        console.log(pt)
        
    })
	
	
	$("#login").on("click",function(){
		if(!getcode){
			login()
		}
		$("#zz").attr("style","display:block;")
	})
	
	$("#loginBtn").on("click",function(){
		if(!getcode){
			login()
		}
		$("#zz").attr("style","display:block;")
	})
	
	$("#closeLogin").on("click",function(){
		$("#zz").attr("style","display:none;")
	})
	
	
	function login(){
		$.ajax({
			url:"/getLoginQrCode",
			type:"GET",
			data:{},
			contentType:"application/json",
			dataType:"json",
			success:function(data){
				if(data.code == 200){
					var img = "data:image/png;base64,"+data.data.qrcode
					getcode = true
					$("#qrcode").attr("src",img)
					$("#qrcode").attr("style","display:block;")
					$(".qrload").attr("style","display:none;")
					stid = data.data.stid
					getState()
				}
			}
		})
	}
	
	function getState(){
		$.ajax({
			url:"/getLoginStatus",
			type:"GET",
			data:{stid:stid},
			contentType:"application/json",
			dataType:"json",
			success:function(data){
				if(data.code == 200){
					if(data.data.state == 0 || data.data.state == 1){
						timeot = setTimeout(getState,1000);
						if(data.data.state == 1){
							$(".succ").attr("style","display:flex;")
							$("#stips").html("扫码成功，请登录")
						}
					}else if(data.data.state == 2){
						clearInterval(timeot)
						location.reload(true)
					}else{
						clearInterval(timeot)
					}
				}
			}
		})
	}
})